
using System;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using Entity;

namespace Data
{
	public class DAPeriodo
	{
	      
        public static DataTable ListarPlanesAdmision()
        {
            SqlDatabase sqlPlanAdmision = new SqlDatabase(Configuracion.GetConnection);
            DbCommand dbCmd = sqlPlanAdmision.GetStoredProcCommand("sp_ListarPlanesAdmision");
            return sqlPlanAdmision.ExecuteDataSet(dbCmd).Tables[0];
        }

        public static DataTable ListarPlanAuditoriaxNro_Nombre(String strIdAuditoria, String strAuditoria)
        {
            SqlDatabase sqlAuditoria = new SqlDatabase(Configuracion.GetConnection);
            DbCommand dbCmd = sqlAuditoria.GetStoredProcCommand("sp_ListarPlanAuditoriaxNro_Nombre");
            sqlAuditoria.AddInParameter(dbCmd, "@strIdAuditoria", DbType.String, strIdAuditoria);
            sqlAuditoria.AddInParameter(dbCmd, "@strAuditoria", DbType.String, strAuditoria);
            return sqlAuditoria.ExecuteDataSet(dbCmd).Tables[0];
        }
        
        public static DataSet ObtenerPeriodoVigente()
		{
			SqlDatabase sql = new SqlDatabase(Configuracion.GetConnection);
			DbCommand dbCmd = sql.GetStoredProcCommand("pDet_ObtenerPeriodoVigente");
	      
	        return sql.ExecuteDataSet(dbCmd);
		}

        public static void RegistrarPeriodo(BEPeriodo oBEPeriodo)
        {
            SqlDatabase sqlClient = new SqlDatabase(Configuracion.GetConnection);

            using (DbConnection connection = sqlClient.CreateConnection())
            {
                connection.Open();
                DbTransaction transaction = connection.BeginTransaction();
                try
                {
                    DbCommand dbCmd = sqlClient.GetStoredProcCommand("sp_InsertPeriodo");

                    sqlClient.AddInParameter(dbCmd, "@CodPeriodo", DbType.String, oBEPeriodo.CodPeriodo);
                    sqlClient.AddInParameter(dbCmd, "@Descripcion", DbType.String, oBEPeriodo.Descripcion);
                    sqlClient.AddInParameter(dbCmd, "@Estado", DbType.Boolean, oBEPeriodo.Estado);
                    sqlClient.AddInParameter(dbCmd, "@UsuCreacion", DbType.String, oBEPeriodo.UsuCreacion);
                    sqlClient.AddInParameter(dbCmd, "@UsuModificacion", DbType.String, oBEPeriodo.UsuModificacion);
                    sqlClient.ExecuteNonQuery(dbCmd);
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw new Exception(ex.Message);
                }
            }
        }

	}
}
      